<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>登录</title>

    <link href="../../css/mui.min.css" rel="stylesheet"/>
    <link href="../../css/common.css" rel="stylesheet"/>
    <link href="../../css/login/index.css" rel="stylesheet"/>
    <script src="../../js/mui.min.js"></script>
    <script src="../../js/vue.min.js"></script>
    <script src="../../js/fastclick.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/api.js"></script>
    <script src="index.js"></script>
</head>
<body>
<div id="app">
    <div class="content-box">
        <div class="top-content">
            <!--标题-->
            <login-header></login-header>
            <!--登录框-->
            <login-input-content  v-model="form" @login="login"></login-input-content>
            <div class="input_outer func-box" @touchstart="goFindPwd">
                忘记密码
            </div>
            <!--登录按钮-->
            <div @click="login" class="xl-btn">登录</div>

        </div>
        <img class="bg-img" src="../../img/login/bg_login_screen.png" alt="">
    </div>
</div>
<script>
    var vm = new Vue({
            el: '#app',
            mounted: function () {

                var param = getRememberUser();
                if (param) {
                    this.form = param;
                }
            },
            data: {
                title: '登录',
                passwordMod: true,
                inputType: 'password',
                form: {
                    userName: '',
                    password: '',
                }
            },
            methods: {
                // 登录
                login: function () {
                    var params = this.form;
                    if (!(params['userName'] && params['password'])) {
                        return mui.toast("请填写完整信息")
                    }
                    params.clientId = plus.push.getClientInfo().clientid;
                    Resource.post(LOGIN_API, params, function (data) {
                        saveUserINfo(data, params);
                        refreshPages();
                    })

                },
                // 跳转密码找回
                goFindPwd: function () {
                    redirect("pages/login/passwordFind.html")
                }
            }
        })
    ;

    // 保存用户登录信息
    function saveUserINfo(data, loginParams) {
        var token = data.token;
        var imgServer = data.imgServer;
        setUserToken(token);
        setImgServer(imgServer);
        setRememberUser(loginParams);
        // 设置用户菜单权限
        setUserPermission(data)
    }

    // 刷新用户页面信息
    function refreshPages() {
        var main = plus.webview.getLaunchWebview();
        plus.webview.show(main, 'fade-in', 100);
        var page = plus.webview.getWebviewById('pages/user/index.html');
        mui.fire(page, 'changeTab', {})
        setTimeout(function () {
            changePage('pages/order/list.html')
        }, 300)
        mui.fire(main, 'selectedIndex', {
            'params': {}
        });
    }

    mui.init();
    // 禁用回退
    mui.init({
        beforeback: function () {
            return false;
        }
    })
</script>
</body>
</html>
